//
//  HTStatesCell.swift
//  weibo
//
//  Created by JonsonLiu on 2017/3/3.
//  Copyright © 2017年 JonsonLiu. All rights reserved.
//

import UIKit
import SnapKit
class HTStatesCell: UITableViewCell {
    
    var comViewConstraint : Constraint?
    
    var statesViewModel : StatesViewModel?{
    
        didSet{
            orgView.statesModel = statesViewModel
            
            comViewConstraint?.deactivate()
            if statesViewModel?.states?.retweeted_status != nil {
                retweentView.isHidden = false
                
                 comView.snp.makeConstraints({ (make) in
                    comViewConstraint = make.top.equalTo(retweentView.snp.bottom).constraint
                })
            }else{
            
                retweentView.isHidden = true
                comView.snp.makeConstraints({ (make) in
                    comViewConstraint = make.top.equalTo(orgView.snp.bottom).constraint
                })
            }
            
        }
    }

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    func setupUI(){
     selectionStyle = .none
//        backgroundColor = UIColor(colorLiteralRed: Float(arc4random()%255)/255, green: Float(arc4random()%255)/255, blue: Float(arc4random()%255)/255, alpha: 1)
        
        contentView.addSubview(orgView)
        contentView.addSubview(comView)
        contentView.addSubview(retweentView)
        
        orgView.snp.makeConstraints { (make) in
            make.leading.top.trailing.equalTo(contentView)
//            make.height.equalTo(150)
        }
        comView.snp.makeConstraints { (make) in
            comViewConstraint = make.top.equalTo(retweentView.snp.bottom).constraint
            make.leading.trailing.equalTo(orgView)
            make.height.equalTo(35)
        }
        
        retweentView.snp.makeConstraints { (make) in
            make.leading.trailing.equalTo(orgView)
            make.top.equalTo(orgView.snp.bottom)
            make.height.equalTo(60)
            
        }
        
        contentView.snp.makeConstraints { (make) in
            make.bottom.equalTo(comView.snp.bottom)
            make.trailing.leading.top.equalTo(self)
        }
        
    }
    
    
    lazy var orgView : HTOrgStateView = HTOrgStateView()
    lazy var comView : HTCommentsView = HTCommentsView()
    lazy var retweentView : HTRetweetStatus = HTRetweetStatus()
    
}
